interface ServiceItem {
  name: string;
  avatar: string;
}

Page({
  data: {
    serviceList: [
      {
        name: '商超百货',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/e4ba31ea1a19fe45c278c9f9af488d6a.jpg'
      },
      {
        name: '交通出行',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/0583d2f08b4d7752d51ef1695ec3abb6.jpg'
      },
      {
        name: '生活服务',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/6ff83026cc0049bb05e87d74248697a2.jpg'
      },
      {
        name: '休闲娱乐',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/b40afdd3dc738955b2b911d776675b72.jpg'
      },
      {
        name: '医疗健康',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/bc771aec7970aec61e39fc6d57f3fc33.jpg'
      },
      {
        name: '教育培训',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/ec77c9f37410c82a8ed38ff27c340a77.jpg'
      },
      {
        name: '旅游度假',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/77e27c3b8796997d7df27822cd0cd274.jpg'
      },
      {
        name: '金融服务',
        avatar: 'https://ai-public.mastergo.com/ai/img_res/45a04079419e73c32433e9cbf28ab126.jpg'
      }
    ],
    showConfirm: false,
    currentIndex: -1
  },

  goBack() {
    // 返回上一页
    wx.navigateBack();
  },

  unfollow(event: WechatMiniprogram.BaseEvent) {
    const index = event.currentTarget.dataset.index as number;
    this.setData({
      currentIndex: index,
      showConfirm: true
    });
  },

  cancelUnfollow() {
    this.setData({
      showConfirm: false,
      currentIndex: -1
    });
  },

  confirmUnfollow() {
    const { currentIndex, serviceList } = this.data;
    if (currentIndex > -1) {
      serviceList.splice(currentIndex, 1);
      this.setData({
        serviceList,
        showConfirm: false,
        currentIndex: -1
      });
    }
  }
});
